package com.wsj.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.wsj.dao.IMagazineNameDao;
import com.wsj.service.IMagazineNameServ;
import com.wsj.util.exception.BusinessException;
import com.wsj.util.page.PageResultSet;
import com.wsj.web.vo.homeSite.MagazineName;

public class MagazineNameServImpl implements IMagazineNameServ {
	
	private IMagazineNameDao magazineNameDao;
	

	public void add(MagazineName magazineName) throws BusinessException {
		if(magazineName!=null){
			this.magazineNameDao.add(magazineName);
		}
	}

	public void delete(MagazineName magazineName) throws BusinessException {
		if(magazineName!=null){
			this.magazineNameDao.delete(magazineName);
		}
	}

	/**
	 * OID 检索
	 * */
	public MagazineName loadById(Integer id) throws BusinessException {
		MagazineName magazineName = new MagazineName();
		if(id!=null){
			magazineName = this.magazineNameDao.loadById(id);
		}
		return magazineName;
	}

	public void update(MagazineName magazineName) throws BusinessException {
		if(magazineName!=null){
			this.magazineNameDao.update(magazineName);
		}
	}

	public List<MagazineName> loadByTime(Integer top) throws BusinessException {
		if(top != null){
			return this.magazineNameDao.loadByTime(top);
		}
		return null;
	}

	
	/**
	 * 分页查询
	 * 条件：期刊名称、刊首语（简介）、是否推荐、是否可读、开始时间、结束时间
	 * 分页条件：页码、每页显示数
	 * 返回：PageResultSet
	 * */
	public PageResultSet loadPageList(String keyWord, String name, Short isCommend, Short iskd, String beginDate, String endDate, Integer page, Integer pageSize) throws BusinessException {
		return this.magazineNameDao.loadPageList(keyWord, name, isCommend, iskd, beginDate, endDate, page, pageSize);
	}

	public List<MagazineName> loadAll() throws BusinessException {
		return this.magazineNameDao.loadAll();
	}

	public Map<String, String> loadMagazineNameMapByInputtime(String year) throws BusinessException {
		Map<String,String> map = new HashMap<String,String>(); 
		List list=this.magazineNameDao.loadMagazineNameByInputtime(year);
		if(list!=null&&list.size()>0){
			for(int i=0; i<list.size(); i++){
				MagazineName magazineName=(MagazineName) list.get(i);
				if(magazineName!=null){
					map.put(magazineName.getId().toString(), magazineName.getQiname());
				}
			}
		}
		
		return map;
	}

	public MagazineName loadByName(String name) throws BusinessException {
		MagazineName magazineName = this.magazineNameDao.loadByName(name);
		return magazineName;
	}

	/**
	 * 检测 期刊名是否被占用 true 被占用
	 * */
	public boolean checkName(String name){
		MagazineName magazineName = this.magazineNameDao.loadByName(name);
		if(magazineName==null){
			return false;
		}
		return true;
	}
	
	public IMagazineNameDao getMagazineNameDao() {
		return magazineNameDao;
	}

	public void setMagazineNameDao(IMagazineNameDao magazineNameDao) {
		this.magazineNameDao = magazineNameDao;
	}

	/*****
	 * 获取最近的八个期刊名
	 *  
	 */
	public List<MagazineName> loadLastMagazineNameListById(Integer magazineNameId) throws BusinessException 
	{
		
		return this.getMagazineNameDao().loadLastMagazineNameListByIdDao(magazineNameId);
	}

	/*****
	 * 获取最新的id
	 */
	public Integer loadMagazineLastId() throws BusinessException 
	{
	
		return this.getMagazineNameDao().loadMagazineLastIdDao();
	}

	public List getMagazineClassListByParentId(Integer magazineNameid) throws BusinessException {
		// TODO Auto-generated method stub
		List list=this.magazineNameDao.getMagazineClassListByParentId(magazineNameid);
		
		return list;
	}

}











